package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/5/21 18:45
 */
@Cmd(code = GameProtocol.S_MANOR_TECHNOLOGY_LEVEL_UP, desc = "庄园科技升级")
public class ManorTechnologyLevelUpCmd extends AbstractCommand {
    private int id;
    private int skillPos;
    private int lvCount;
    private ManorProto.ManorTechnologyLevelUpRespMsg.Builder respMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ManorProto.ManorTechnologyLevelUpReqMsg msg = ManorProto.ManorTechnologyLevelUpReqMsg.parseFrom(packet.getBytes());
        id = msg.getId();
        skillPos = msg.getSkillPos();
        lvCount = msg.getLvCount();
        respMsg = ManorProto.ManorTechnologyLevelUpRespMsg.newBuilder();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.getModule(ManorModule.class).technologyLevelUp(id, skillPos, lvCount, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        player.sendPacket(ClientProtocol.U_MANOR_TECHNOLOGY_LEVEL_UP, respMsg);
    }
}
